home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DLLCust_Files / TRANSFRM / CROSCORR.C < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  1.8 KB  |  64 lines

  1. // Dynamic link library implementation of NeuroSolutions Axon component 
  2.  
  3. #include "NSDLL.h" 
  4.  
  5. /****************************/
  6. /* Transform implementation */
  7.  
  8. __declspec(dllexport) BOOL performTransform(
  9.     DLLData    *instance,    // Pointer to instance data
  10.     NSFloat    *data,         // Pointer to the buffered data
  11.     int     length,        // Length of the buffer to be transformed
  12.     int     channel        // Current channal number
  13.     )
  14. {
  15.     NSFloat *corr, *firstChannel=(NSFloat*)getUserData(instance);
  16.     BOOL    displayChannel=FALSE;
  17.     int    i, j, start=0,
  18.         channel1=getIntParameter(instance, 2, 1),
  19.         channel2=getIntParameter(instance, 2, 2);
  20.  
  21.     if ((channel == channel1) || (channel == channel2)) {
  22.         if (channel1 == channel2)
  23.             firstChannel = data;
  24.         if (firstChannel) {
  25.             corr = (NSFloat*)calloc(length, sizeof(NSFloat));
  26.             for (i=0; i<length; i++) {
  27.                 for (j=start; j<length; j++) 
  28.                     corr[i] += data[j]*firstChannel[j-start];
  29.                 start++;
  30.             }
  31.             for (i=0; i<length; i++)
  32.                 data[i] = corr[i];
  33.             setUserData(instance, NULL); 
  34.             displayChannel = TRUE;
  35.             free(corr);
  36.         } else
  37.             setUserData(instance, data);
  38.     }
  39.     return displayChannel;
  40. }
  41.  
  42. /******************************************/
  43. /* Management of instance data (OPTIONAL) */
  44.  
  45. __declspec(dllexport) DLLData *allocTransform(
  46.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  47.     int     length,        // Length of the buffer to be transformed
  48.     int     channels    // Number of channels to be transformed
  49.     )
  50. {
  51.     DLLData *instance = allocDLLInstance(oldInstance);
  52.     setParameterName(instance, 2, 1, "Chan X", FALSE);
  53.     setIntParameter(instance, 2, 1, 0, FALSE);
  54.     setParameterName(instance, 2, 2, "Chan Y", FALSE);
  55.     setIntParameter(instance, 2, 2, 1, FALSE);
  56.     return instance;
  57. }
  58.  
  59. __declspec(dllexport) void freeTransform(DLLData *instance)
  60. {
  61.     freeDLLInstance(instance);
  62. }
  63.  
  64.